﻿using Pay.Core;
using Pay.DTO;
using Pay.IService;
using Pay.TO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Pay.Distribution.Controllers {
    public class ShippingPositionController : GeneralController
    {
        private IShippingPositionService _iShippingPositionService;
        private IMerchantService _iMerchantService;

        public ShippingPositionController(IShippingPositionService iShippingPositionService, IMerchantService iMerchantService)
        {
            _iShippingPositionService = iShippingPositionService;
            _iMerchantService = iMerchantService;
        }

        [HttpGet]
        public JsonResult Gets(ShippingPositionQuery query)
        {
            var result = _iShippingPositionService.Get(query);
            return Json(ResultToJson.Json(result), JsonRequestBehavior.AllowGet);
        }

        [HttpGet]
        public JsonResult Get(long id)
        {
            var result = _iShippingPositionService.Get(id);
            return Json(ResultToJson.Json(result), JsonRequestBehavior.AllowGet);
        }

        [AcceptVerbs(HttpVerbs.Post | HttpVerbs.Put)]
        [ValidateInput(false)]
        public JsonResult Save(shipping_position_dto model)
        {
            var merchant = _iMerchantService.Get(currentUser.user_id);
            model.merchant_id = merchant.id;
            var result = _iShippingPositionService.Save(model);
            return Json(ResultToJson.Json(result != 0 ? "保存成功" : "保存失败", result), JsonRequestBehavior.AllowGet);
        }

        [HttpDelete]
        public JsonResult Delete(long id)
        {
            var result = _iShippingPositionService.Delete(new List<long> { id });
            return Json(ResultToJson.Json(result > 0 ? " 删除成功" : "删除失败", result), JsonRequestBehavior.AllowGet);
        }
    }
}